package com.lap.generator.commons.tools;

import com.lap.framework.tools.Named;
import java.util.Arrays;
import java.util.stream.Collectors;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;

/**
 * 包工具
 *
 * @author Shuisheng Lao(劳水生)
 * @version 0.0.1
 */
public final class PackageUtil {

  private PackageUtil() {}

  /**
   * 包转换到路径
   *
   * @param packageNames 包名字
   * @return 目录路径
   */
  public static String pack2Path(String... packageNames) {
    if (ArrayUtils.isEmpty(packageNames)) return Constants.EMPTY;

    StringBuilder result = new StringBuilder();
    for (String string : packageNames) {
      if (StringUtils.isNotBlank(string)) {
        result.append(Named.periods2Path(string));
      }
    }
    return result.toString();
  }

  /**
   * 多个包拼接
   *
   * @param packageNames 包名
   * @return 包
   */
  public static String pack(String... packageNames) {
    return Arrays.stream(packageNames).collect(Collectors.joining("."));
  }
}
